import java.util.ArrayList;
import java.util.List;

public class WordBreak {

    public boolean wordBreak(String s, List<String> wordDict) {
        List<String> tempList=new ArrayList<>();
        for (String s1 : wordDict) {
            if(s.contains(s1)){
                tempList.add(s1);
            }
        }
        for (String temps : tempList) {
            s=s.replace(temps,"");
        }

        return "".equals(s);
    }
}
